﻿using log4net;
using System;
using System.Collections.Generic;
using System.Reflection;
using TradePublish.Entity;
using TradePublish.Dao;

public class ApplyUserContractManager
{
    private ApplyUserContractDao applyUserContractDao;
    private ILog log = null;

    public ApplyUserContractManager()
    {
        this.log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        this.applyUserContractDao = new ApplyUserContractDao();
    }
 

    public void saveContract(List<ApplyUserContract> contracts)
    {
        String officalWebsite="";//OFFICAL_WEBSITE    VARCHAR(200)   官网
        int haveOfficeWebsite=0;//HAVE_OFFICE_WEBSITE SMALLINT  是否有官网  0-无  1-有
        int havaEmail=0;//HAVE_EMAIL   SMALLINT    是否有邮箱 0-无 1-有  2-QQ邮箱
        int haveTelephone=0;//HAVE_TELEPHONE   SMALLINT    是否有电话 0-无 1-有
        int haveWangwang=0;//HAVE_WANGWANG   SMALLINT    是否有旺旺号 0-无 1-有

        foreach (ApplyUserContract contract in contracts)
        {
            if (contract.officalWebsite != null && !contract.officalWebsite.Equals(""))
            {
                haveOfficeWebsite = 1;
                officalWebsite = contract.officalWebsite;
            }
            else
            {
                contract.officalWebsite = "";
            }
            if (contract.email == null || contract.email.Equals(""))
            {
                contract.email = "";
            }
            else if (contract.email.IndexOf("qq.com") >= 0) {
                havaEmail = 2;
            }
            else if (havaEmail !=2)
            {
                havaEmail = 1;
            }
            #region 
            if (contract.emailSourceHtml == null)
            {
                contract.emailSourceHtml = "";
            }
            if (contract.fax == null)
            {
                contract.fax = "";
            }
            if (contract.msn == null)
            {
                contract.msn = "";
            }
            if (contract.qq == null)
            {
                contract.qq = "";
            }
            if (contract.telephone == null)
            {
                contract.telephone = "";
            }
            if (contract.telephoneSourceHtml == null)
            {
                contract.telephoneSourceHtml = "";
            }
            #endregion
            if (contract.wangwangNo == null || contract.wangwangNo.Equals(""))
            {
                contract.wangwangNo = "";
            }
            else
            {
                haveWangwang = 1;
            }
            if (contract.wangwangHtml == null)
            {
                contract.wangwangHtml = "";
            }
        }
        foreach (ApplyUserContract contract in contracts)
        {
            contract.haveOfficeWebsite = haveOfficeWebsite;
            contract.haveEmail = havaEmail;
            contract.haveTelephone = 0;
            contract.haveWangwang = haveWangwang;
            if (contract.officalWebsite == null || contract.officalWebsite.Equals(""))
            {
                contract.officalWebsite = officalWebsite;
            }
        }
        this.applyUserContractDao.saveContract(contracts);
    }
}

